package com.boruishangge.home.viewhelp;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

import androidx.viewpager.widget.ViewPager;

import com.boruishangge.home.bean.HomeTabBean;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.ArrayList;
import java.util.List;

public class TableActivityViewHelp {
    public static void initMagicIndicator(MagicIndicator lvMagicIndicator, final ViewPager lvViewPager, List<HomeTabBean> dataBeanListv, Context context) {
        final List<HomeTabBean> dataBeanList = new ArrayList<>();
        dataBeanList.clear();
        dataBeanList.addAll(dataBeanListv);
        CommonNavigator commonNavigator = new CommonNavigator(context);
        commonNavigator.setAdjustMode(true);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {
            @Override
            public int getCount() {
                return dataBeanList.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
                simplePagerTitleView.setNormalColor(Color.parseColor("#ff333333"));
                simplePagerTitleView.setSelectedColor(Color.parseColor("#ff1D81FF"));
                simplePagerTitleView.setText(dataBeanList.get(index).getName());
                simplePagerTitleView.setTextSize(14);
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        lvViewPager.setCurrentItem(index);
                         }
           });

                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
                linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
                linePagerIndicator.setRoundRadius(UIUtil.dip2px(context, 2));
                linePagerIndicator.setColors(Color.parseColor("#ff1D81FF"));
                linePagerIndicator.setStartInterpolator(new AccelerateInterpolator());
                linePagerIndicator.setEndInterpolator(new DecelerateInterpolator(1.0f));
                return linePagerIndicator;
            }
        });
        lvMagicIndicator.setNavigator(commonNavigator);
        ViewPagerHelper.bind(lvMagicIndicator, lvViewPager);
    }
    public  static    List<HomeTabBean>  getTabData(){
        List<HomeTabBean> homeTabBe = null;
        if (homeTabBe==null){
            homeTabBe=   new ArrayList<>();
        }
        homeTabBe.clear();
        for (int i = 0; i <4; i++){
            HomeTabBean homeTabBean=new HomeTabBean();
            if (i==0){
                homeTabBean.setName("FOOD");
            }else if (i==1){
                homeTabBean.setName("DRINK");
            }else if (i==2){
                homeTabBean.setName("套餐");
            }else {
                homeTabBean.setName("店员点餐");
            }
            homeTabBean.setId(i);
            homeTabBe.add(homeTabBean);
        }
        return  homeTabBe;
    }
}
